﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    
</body>
</html>
<script type="text/javascript">
    String.prototype.replaceAll = function (oldVal, newVal) {
        return this.replace(new RegExp(oldVal, "gm"), newVal);
    }

    var temp = "abc-abc-abc";
    //alert(temp.replaceAll('a', 'x'));

    /*继承原型，重新指向原来的构造函数constructor*/
    function inheritPrototype(subType, superType) {
        var prototype = Object(superType.prototype);
        prototype.constructor = subType;
        subType.prototype = prototype;
    }

    /*父类---带参数的构造函数*/
    function Person(name)
    {
        this.name = name;
    }

    Person.prototype.say = function () {
        return "hello " + this.name;
    }

    /*子类*/
    function Man(age, name) {
        this.name = name + "1";
        this.age = age;

        Person.call(this, [name]);

        //this.say = function () {
        //    return "hello " + this.name + "1";
        //}
    }

    inheritPrototype(Man, Person);

    Man.prototype.say = function () {
        return "hello " + this.name + "2";
    }

    var m = new Man("12", "aaa");
    //alert(m.constructor);
    alert(m.say());

    /*父类---不带参数的构造函数*/
    function Person1() {
        this.name = "abc";
    }
    Person1.prototype.say = function () {
        return "hello " + this.name;
    }

    /*子类*/
    function Man1() {

    }

    Man1.prototype = new Person1();
    var m1 = new Man1();
    //alert(m1.name);
</script>